﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace myinfo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox3.Clear();
            bool b1 = Directory.Exists(@textBox1.Text);
            if (!b1)
            {
                Directory.CreateDirectory(@textBox1.Text);
                textBox3.Text += "创建目录、 ";
            }
            String fileName = textBox1.Text + "\\" + textBox2.Text;
            bool b2 = File.Exists(@fileName);
            if (!b2)
            {
                textBox3.Text += "文件 ";
            }
            
            StreamWriter sw = new StreamWriter(@fileName);
            sw.WriteLine(richTextBox1.Text);
            sw.Flush();
            sw.Close();
            richTextBox1.Clear();
            textBox3.Text += "写入成功";

        }

        private void button2_Click(object sender, EventArgs e)
        {
            richTextBox2.Clear();
            String fileName = textBox1.Text +"\\" + textBox2.Text;
            bool b1 = Directory.Exists(@textBox1.Text);
            bool b2 = File.Exists(@fileName);
            if (!b1)
            {
                MessageBox.Show("文件路径不存在");
            }else if(!b2)
            {
                MessageBox.Show("文件不存在");
            }
            else {
                StreamReader rd1 = new StreamReader(@fileName);
                string line;
                while ((line = rd1.ReadLine()) != null)
                {
                    richTextBox2.Text += line + "\n";
                }
                rd1.Close();
            }
 

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
